from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base

# 创建数据库连接字符串
SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"  # 先用 SQLite 测试，之后换 MySQL 也可以

engine = create_engine(
    SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)

SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()  # 补上 Base！！！

def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()
